Simulation of Genshin Impact's wishes

Recently, the game named Genshin Impact become extremely popular across the gamming community, but the rule of wishes is criticized by many player.

  • Objective: In this mini-project, we aim to obtain a overall probability of getting a 5-star charactors if we have unlimited wishes.

  • Given rule: standard wishes has 0.6% of probability of 5-star charactors, while guaranteed every for every 90 draws without 5-star charactors.

  • Method: I am going to simulate 5000 consective wishes for 150 individual trials. The final probability is the average of the probablity of 150 trials.

  • Result: we have expected probablity of 1.43% for 5-star under a unlimited withes condition.

In [1]:
import numpy as np
import matplotlib.pyplot as plt
import random
import pandas as pd
In [2]:
# experiment setup
n_repeat = 5*10**3
p_success = 0.006
n_trial = 150
In [3]:
def n_repeat_Bernoulli_experiment_wt_guaranteed(n_repeat,p_success):
    failure_count = 0
    failure_count_ls = []
    result_ls = []
    prob_ls = []
    
    for k in np.arange(1,n_repeat+1):
        # draw trail result from Bernoulli distribution
        trail = random.choices([1, 0], weights=(p_success, 1-p_success), k = 1)
        # count if fail
        if trail == [0]:
            failure_count += 1 
        if trail == [1]:
            failure_count = 0
        # Guaranteed within 90 draws
        if failure_count == 90:
            trail = [1]
            failure_count = 0
        # record result
        failure_count_ls.append(failure_count)
        result_ls += trail
        prob_ls.append(sum(result_ls)/len(result_ls))
        
    return result_ls, failure_count_ls, prob_ls
In [4]:
# collect simulation data
simulation_final = []
for k in np.arange(1, n_trial+1):
    _, _, prob_ls = n_repeat_Bernoulli_experiment_wt_guaranteed(n_repeat, p_success)
    simulation_final.append(prob_ls[-1])
    plt.plot(np.arange(1,n_repeat+1), prob_ls, linewidth=1, alpha = .1)
plt.title('The simulation of probablity of drawing five-star charactors (' + str(n_trial) +'-trial)')
plt.xlabel('# of repetition')
plt.ylabel('probablity of sucess')
plt.yscale('log')
plt.axhline(sum(simulation_final)/len(simulation_final), linewidth=1, color='g')
plt.text(x = n_repeat/2, 
         y = sum(simulation_final)/len(simulation_final)*1.1,
         s = 'p = ' + str(sum(simulation_final)/len(simulation_final)))
Out[4]:
Text(2500.0, 0.015581866666666678, 'p = 0.014165333333333342')

As shown in the above graph of the probability along the repeatition, the variance diminishes as increasing repetition and the probablity of drawing five-star charactors converge to the value marked above.

In [5]:
print('Probablity:', sum(simulation_final)/len(simulation_final))
print('Standard deviation:', np.std(simulation_final))
Probablity: 0.014165333333333342
Standard deviation: 0.0007120848888221748
In [6]:
# Additionally:
print("The total probability of the success from standard draws:", 0.6/100)
print("The total probability of the success from guaranteed draws:", 1/90)
print("The total probability of the success from standard draws and guaranteed draws:", 0.6/100 + 1/90)
plt.hist(simulation_final)
The total probability of the success from standard draws: 0.006
The total probability of the success from guaranteed draws: 0.011111111111111112
The total probability of the success from standard draws and guaranteed draws: 0.01711111111111111
Out[6]:
(array([ 3., 15., 21., 30., 23., 29., 13.,  8.,  6.,  2.]),
 array([0.0126 , 0.01296, 0.01332, 0.01368, 0.01404, 0.0144 , 0.01476,
        0.01512, 0.01548, 0.01584, 0.0162 ]),
 <BarContainer object of 10 artists>)